<template>
    <view class="pub_page pub_mine_index pub_tabbar_padding">
        <pub-tabbar :active="3"></pub-tabbar>
        <pub-dialog v-show="dialogShow" dialogName="mine_index" :dialogConfig="dialogConfig"
            @dialogBack="dialogBack"></pub-dialog>
        <div class="page_box" v-if="userInfo!=''">
            <div class="user_div" @click="$comFun.openWin('/pages/mine/info')">
                <pub-image class="headimg" :src="userInfo.avatar" :mode="'aspectFill'"></pub-image>
                <div class="text">
                    <div class="name">
                        <div class="span_1" :class="userInfo.vipAccount==1?'':'span_1_no'"
                            @click.stop="pageDeal('open_vip_account')"></div>
                        <div class="span" :class="userInfo.vipAccount==1?'span_red':''">{{ userInfo.nickName }}</div>
                        <div class="span_2" v-if="userInfo.isVipGrade==1"></div>
                        <div class="span_3">Lv.{{ userInfo.grade }}</div>
                    </div>
                    <div class="labels" @click.stop="$comFun.openWin('/pages/mine/label')">
                        <div class="li" v-for="(li,key) in myLabel" :key="key">
                            <pub-image class="img" :src="li.coverImg"></pub-image>
                            <div class="txt">{{ li.title }}</div>
                        </div>
                        <div class="li">
                            <pub-image class="img" :src="'../../static/aimg/img_33.png'"></pub-image>
                            <div class="txt">添加</div>
                        </div>
                    </div>
                    <div class="invi_txt">我的邀请码：{{ userInfo.invitationCode }} <text class="copy"
                            @click.stop="$comFun.toCopy(userInfo.invitationCode)">复制</text></div>
                </div>
                <!-- <pub-image class="invite" :src="'../../static/aimg/img_34.png'" @imgClick="$comFun.openWin('/pages/mine/invite')"></pub-image> -->
            </div>
            <div class="nums_div">
                <div class="vip">
                    <div class="icon"></div>
                    <div class="p_1"></div>
                    <div class="p_2" v-if="userInfo.isVipGrade==0">成为 ChatterBox 会员享受更多权益</div>
                    <div class="p_2" v-if="userInfo.isVipGrade==1">到期时间：{{ userInfo.vipExpireTime }}</div>
                    <div class="btn" @click="pageDeal('open_vip_grade')">{{userInfo.isVipGrade==0?'立即支付':'立即续费'}}</div>
                </div>
                <div class="num">
                    <div class="li">
                        <div class="left" @click="$comFun.openWin('/pages/mine/log', { openType: 1 })">CTT:<span
                                class="span">{{ userInfo.integral }}</span> 个</div>
                        <div class="pub_btn" @click="$comFun.openWin('/pages/mine/cttSend')">转赠</div>
                    </div>
                </div>
                <div class="num">
                    <div class="li">
                        <div class="left" @click="$comFun.openWin('/pages/mine/log', { openType: 2 })">金币:<span
                                class="span">{{ userInfo.coin }}</span> 个</div>
                        <div class="pub_btn" @click="$comFun.openWin('/pages/mine/cttSend',{giveType:2})">转赠</div>
                    </div>
                </div>
                <div class="num">
                    <div class="li">
                        <div class="left" @click="$comFun.openWin('/pages/mine/log', { openType: 3 })">USDT:<span
                                class="span">{{ userInfo.usd }}</span>
                        </div>
                        <div class="pub_btn_a">
                            <div class="pub_btn pub_btn_1" @click="$comFun.openWin('/pages/mine/usdt_withdraw')">
                                提现</div>
                            <div class="pub_btn pub_btn_1" @click="$comFun.openWin('/pages/mine/usdt_recharge')">
                                充值</div>
                            <div class="pub_btn pub_btn_1" @click="$comFun.openWin('/pages/mine/cttSend',{giveType:3})">
                                转赠</div>
                        </div>
                    </div>
                </div>
                <!-- <div class="num_1" v-if="userOtherInfo != ''">
                    <div class="li li_1">
                        <div class="p_1">今日奖励</div>
                        <div class="p_2"><span class="txt">{{ userOtherInfo.dayReceiveCttNum }}</span> <span
                                class="txt_o">CTT</span></div>
                    </div>
                    <div class="li li_2">
                        <div class="p_1">今日添加好友</div>
                        <div class="p_2"><span class="txt">{{ userOtherInfo.dayAddFriendNum }}</span></div>
                    </div>
                    <div class="li li_3">
                        <div class="p_1">今日被添加</div>
                        <div class="p_2"><span class="txt">{{ userOtherInfo.dayBeAddFriendNum }}</span> <span
                                class="txt_o">剩余被添加 {{ userOtherInfo.surplusBeAddFriendNum }} 次</span></div>
                    </div>
                </div> -->
            </div>
            <div class="tools_div">
                <div class="li" @click="$comFun.openWin('/pages/mine/invite',{invitationCode:userInfo.invitationCode})">
                    <pub-image class="img" :src="'../../static/aimg/img_25.png'"></pub-image>
                    <div class="txt">邀请码</div>
                </div>
                <!-- @click="openMeiQia" -->
                <div class="li" @click="fwsClick">
                    <pub-image class="img" :src="'../../static/aimg/img_26.png'"></pub-image>
                    <div class="txt">服务商</div>
                </div>
                <div class="li" @click="$comFun.openWin('/pages/mine/friend')">
                    <pub-image class="img" :src="'../../static/aimg/img_46.png'"></pub-image>
                    <div class="txt">朋友圈</div>
                </div>
                <div class="li" @click="$comFun.openWin('/pages/mine/team')">
                    <pub-image class="img" :src="'../../static/aimg/img_28.png'"></pub-image>
                    <div class="txt">我的朋友圈</div>
                </div>
                <div class="li" @click="$comFun.openWin('/pages/other/document', { id: '1759912500717932545' })">
                    <pub-image class="img" :src="'../../static/aimg/img_29.png'"></pub-image>
                    <div class="txt">话匣子法律</div>
                </div>
                <div class="li_big" @click="$comFun.openWin('/pages/other/notice')">
                    <pub-image class="img" :src="'../../static/aimg/img_30.png'"></pub-image>
                    <div class="txt">平台公告</div>
                    <text class="icon-font-basic icon-b-arrow-1-2"></text>
                </div>
                <div class="li_big" @click="$comFun.openWin('/pages/other/set')">
                    <pub-image class="img" :src="'../../static/aimg/img_31.png'"></pub-image>
                    <div class="txt">我的设置</div>
                    <text class="icon-font-basic icon-b-arrow-1-2"></text>
                </div>
            </div>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            userInfo: '',
            userOtherInfo: '',
            myLabel: [],

            dialogShow: false,
            dialogType: '',
            dialogConfig: {
                title: '提示',//标题栏内容
                content: ''
            },

            vipAmountPrice: 0,
            vipPrice: '',

            mqModule: '',

            fwsInfo: ''
        };
    },
    onLoad() {
        this.getConfig();

        // #ifdef APP-PLUS
        this.mqModule = uni.requireNativePlugin("MeiQia-ChatPlugin");
        // #endif
    },
    onShow() {
        this.getInfo();
        this.getLabelInfo();
    },
    methods: {
        async fwsClick() {
            if (this.fwsInfo != '') {
                this.$comFun.openWin('/pages/mine/fws', {
                    images: this.fwsInfo
                })
                return;
            }
            const res = await this.$request.get('public/getAd', {
                key: 'service-ad'
            });
            // console.log(res);
            if (res.code == 200 && res.result.length > 0 && res.result[0].image) {
                this.fwsInfo = res.result[0].image
                this.$comFun.openWin('/pages/mine/fws', {
                    images: this.fwsInfo
                })
            } else {
                this.$comFun.toast('敬请期待');
            }
        },
        openMeiQia() {
            this.mqModule.initChatViewManger();
            this.mqModule.setLoginCustomizedId(this.userInfo.mobile);
            this.mqModule.configChatViewStyle({
                "navBarBackgroundColor": "#1661F6", // 设置导航栏的背景色；
                "navBarTitleTxtColor": "#ffffff", // 设置导航栏上的 title 的颜色；
                "enableShowClientAvatar": true, // 是否支持当前用户头像的显示
            });
            this.mqModule.showMeiQiaChatView();
        },
        dialogBack(data) {
            console.log(data);
            this.dialogShow = false;
            if (data.name == 'mine_index' && data.key == 1) {
                this.pageDeal(this.dialogType)
            }
        },
        async getInfo() {
            if (this.userInfo == '') {
                this.$comFun.openLoading();
            }
            const res = await this.$request.get('user/userInfo', {});
            // const res_1 = await this.$request.get('user/getPersonalCenter', {});
            if (this.userInfo == '') {
                this.$comFun.closeLoading();
            }
            // console.log(res);
            if (res.code == 200) {
                this.userInfo = res.result;
            }
            // if (res_1.code == 200) {
            //     this.userOtherInfo = res_1.result;
            // }
        },
        async getLabelInfo() {
            const res = await this.$request.get('quan/getMyLabelList', {});
            // console.log(res);
            if (res.code == 200) {
                this.myLabel = res.result.splice(0, 5);
            }
        },
        async getConfig() {
            let configRes = await getApp().getConfigList();
            // console.log(configRes);
            this.vipAmountPrice = configRes.vipAmountPrice;
            this.vipPrice = configRes.vipPrice;
        },
        async pageDeal(type) {
            switch (type) {
                case 'open_vip_account':
                    if (this.userInfo.vipAccount == 1) return;
                    this.dialogShow = true;
                    this.dialogType = 'sure_vip_account';
                    this.dialogConfig = {
                        title: '提示',//标题栏内容
                        content: `是否使用 ${this.vipAmountPrice} 金币开通靓号会员？`
                    }
                    break;
                case 'sure_vip_account':
                    this.$comFun.openLoading();
                    const res = await this.$request.get('user/buyVipAccount', {});
                    this.$comFun.closeLoading();
                    // console.log(res);
                    if (res.code == 200) {
                        this.$comFun.toast('开通成功');
                        this.getInfo();
                    } else {
                        this.$comFun.toast(res.message)
                    }
                    break;
                case 'open_vip_grade':
                    this.dialogShow = true;
                    this.dialogType = 'sure_vip_grade';
                    this.dialogConfig = {
                        title: '提示',//标题栏内容
                        content: `是否使用 ${this.vipPrice} 金币${this.userInfo.isVipGrade == 0 ? '开通' : '续费'}VIP？`
                    }
                    break;
                case 'sure_vip_grade':
                    this.$comFun.openLoading();
                    const res_1 = await this.$request.get('user/renewalVip', {});
                    this.$comFun.closeLoading();
                    // console.log(res_1);
                    if (res_1.code == 200) {
                        this.$comFun.toast(`${this.userInfo.isVipGrade == 0 ? '开通' : '续费'}成功`);
                        this.getInfo();
                    } else {
                        this.$comFun.toast(res_1.message)
                    }
                    break;
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
